package com.zcxy.sys.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zcxy.anotation.Log;
import com.zcxy.core.bean.PageQuery;
import com.zcxy.core.bean.Response;
import com.zcxy.sys.entity.SysAutocodeItem;
import com.zcxy.sys.pojo.SysAutocodeItemVo;
import com.zcxy.sys.service.ISysAutocodeItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.List;

/**
 * @author zcc
 * @version 1.0.0
 * @ClassName "SysAutocodeItem"Controller.java
 * @Description "代码生成"
 * @createTime 2020-09-12
 */
@RestController
@RequestMapping("/api/sysAutocodeItem")
@Api(tags = "代码生成管理")
@Slf4j
public class SysAutocodeItemController {
    @Autowired
    private ISysAutocodeItemService iSysAutocodeItemService;

    @Log("获取代码生成数据--分页")
    @PostMapping(value = "/queryPageList")
    @ApiOperation(value = "获取(代码生成)分页数据列表", notes = "获取(代码生成)分页数据列表")
    public Response<IPage<SysAutocodeItemVo>> queryPageList(@RequestBody PageQuery<SysAutocodeItem> queryVo) {
        return Response.ok(iSysAutocodeItemService.queryPageList(queryVo));
    }

    @Log("获取代码生成数据-列表")
    @GetMapping(value = "/queryList")
    @ApiOperation(value = "获取代码生成数据-列表", notes = "获取代码生成数据-列表")
    public Response<List<SysAutocodeItemVo>> queryList() {
        return Response.ok(iSysAutocodeItemService.queryList());
    }


    @Log("添加代码生成数据")
    @PostMapping(value = "/add")
    @ApiOperation(value = "添加代码生成数据", notes = "添加代码生成数据")
    public Response addSysAutocodeItem(@RequestBody @Validated @NotNull SysAutocodeItem queryVo) {
        iSysAutocodeItemService.addSysAutocodeItem(queryVo);
        return Response.ok();
    }


    @Log("修改代码生成数据")
    @PostMapping(value = "/update")
    @ApiOperation(value = "修改代码生成数据", notes = "修改代码生成数据")
    public Response updateSysAutocodeItem(@RequestBody @Validated @NotNull SysAutocodeItemVo queryVo) {
        iSysAutocodeItemService.updateSysAutocodeItem(queryVo);
        return Response.ok();
    }


    @Log(value = "批量删除代码生成")
    @ApiOperation("批量删除代码生成")
    @DeleteMapping("/dels")
    public Response deleteByIds(@RequestBody List<String> ids) {
        iSysAutocodeItemService.removeAllSysAutocodeItem(ids);
        return Response.ok();
    }


    @Log("导出代码生成")
    @ApiOperation("导出代码生成")
    @PostMapping(value = "/download")
    public void download(HttpServletResponse response, @RequestBody SysAutocodeItem queryVo) throws IOException {
        try {
            iSysAutocodeItemService.download(queryVo, response);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
